package cn.btks.resultintegration.catalog.controller;

import cn.btks.commonserver.result.Constants;
import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.commonserver.util.GeoUtils;
import cn.btks.resultintegration.catalog.dto.CatalogDto;
import cn.btks.resultintegration.catalog.dto.CatalogWithFileTreeDto;
import cn.btks.resultintegration.catalog.dto.FileCatalogDto;
import cn.btks.resultintegration.catalog.pojo.Catalog;
import cn.btks.resultintegration.catalog.service.CatalogService;
import cn.btks.resultintegration.catalog.service.FileCatalogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author lijun
 * @Date 2020/12/14 17:32
 */
@RestController
@RequestMapping("api/v1.0/resultIntegration/policyFile")
@Api(tags = "文件目录结构模块")
@Validated
public class FileCatalogController {

    @Autowired
    FileCatalogService catalogService;

    @GetMapping("/findAll")
    @ApiOperation("《文件目录》查询所有目录信息(树结构)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll() {
        List<FileCatalogDto> catalogList = catalogService.findAll();
        return catalogList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), catalogList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/findCatalogWithFileTree")
    @ApiOperation("《文件目录》查询所有目录信息(树结构,包含文件)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findCatalogWithFileTree() {
        List<CatalogWithFileTreeDto> catalogList = catalogService.findCatalogWithFileTree();
        return catalogList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), catalogList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/findCatalogWithFileTreeByCatalogId")
    @ApiOperation("《文件目录》根据目录ID查询所有目录信息(树结构,包含文件)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findCatalogWithFileTreeByCatalogId(Long id) {
        List<CatalogWithFileTreeDto> catalogList = catalogService.findCatalogWithFileTreeByCatalogId(id);
        return catalogList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), catalogList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }
}
